/*
 * Copyright 2010-2012 Susanta Tewari. <freecode4susant@users.sourceforge.net>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package gui.genomemap.inputModel;

import genomemap.data.RFLPImputation;

import gui.genomemap.inputModel.optOperations.ComGLHoodOptionalOperModel;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.OneToOne;

/**
 * the input model corresponding to the worker ComGLHood.
 * This will have all the parameters for GDataSource and some for GLikelihood. One should
 * be able to create an instance of GDataSource from this model.
 * @author Susanta Tewari
 * @version 1.0
 * @created 16-Nov-2007 11:23:09 AM
 */
@Entity
public class ComGLHoodIModel extends InputModel implements java.io.Serializable {

    /** Field description */
    private int iterationLimit = 150;

    /** Field description */
    private double convgEpsilon = 1.0E-4;

    /** Field description */
    @OneToOne(cascade = CascadeType.ALL)
    private RFLPImputation rflpImputation = new RFLPImputation();

    /** Field description */
    @OneToOne(cascade = CascadeType.ALL)
    private ComGLHoodOptionalOperModel optionalOperModel = new ComGLHoodOptionalOperModel();

    /**
     * Constructs ...
     */
    public ComGLHoodIModel() {}

    public static void main(String[] args) {

        ComGLHoodIModel inputModel = new ComGLHoodIModel();

        System.out.println(inputModel.getOptionalOperModel().isComputingSE());
    }

    @Override
    public int hashCode() {

        return super.hashCode() + new Integer(iterationLimit).hashCode()
               + new Double(convgEpsilon).hashCode() + getRflpImputation().hashCode();
    }

    /**
     * Note that <CODE>optionalOperModel</CODE> is not included in the <CODE>hashCode</CODE>
     * and <CODE>equals</CODE> implementation. This is to differentiate between the
     * core input setings that would require a fresh LHood computation from optional
     * operations which do not require a fresh LHood computation except for few
     * (SE computation if the accuracy wasn`t up to the required level).
     */
    @Override
    public boolean equals(Object obj) {

        if (obj instanceof ComGLHoodIModel) {

            if (super.equals(obj)) {

                ComGLHoodIModel inputModel = (ComGLHoodIModel) obj;

                return (this.getIterationLimit() == inputModel.getIterationLimit())
                       && (this.getConvgEpsilon() == inputModel.getConvgEpsilon())
                       && this.getRflpImputation().equals(inputModel.getRflpImputation());
            }

            return false;
        }

        return false;
    }

    public int getIterationLimit() {
        return iterationLimit;
    }

    public void setIterationLimit(int iterationLimit) {
        this.iterationLimit = iterationLimit;
    }

    public double getConvgEpsilon() {
        return convgEpsilon;
    }

    public void setConvgEpsilon(double convgEpsilon) {
        this.convgEpsilon = convgEpsilon;
    }

    public ComGLHoodOptionalOperModel getOptionalOperModel() {
        return optionalOperModel;
    }

    public void setOptionalOperModel(ComGLHoodOptionalOperModel optionalOperModel) {
        this.optionalOperModel = optionalOperModel;
    }

    public RFLPImputation getRflpImputation() {
        return rflpImputation;
    }

    public void setRflpImputation(RFLPImputation rflpImputation) {
        this.rflpImputation = rflpImputation;
    }
}
